﻿using FarmSmartSleep.Common.Domain.PM;
using FarmSmartSleep.Common.Dtos;
using FarmSmartSleep.Common.Infrastructure;
using MediatR;

namespace FarmSmartSleep.Organ.API.Application.ProductionManagement.MotherHybridizationCommands
{
    public class MotherHybridizationDetailHander : IRequestHandler<MotherHybridizationDetailCommand, ResultT<MotherHybridization>>
    {

        private readonly IBaseRepository<MotherHybridization> baseRepository;
        private readonly ILogger<MotherHybridizationDetailHander> logger;

        public MotherHybridizationDetailHander(IBaseRepository<MotherHybridization> baseRepository, ILogger<MotherHybridizationDetailHander> logger)
        {
            this.baseRepository = baseRepository;
            this.logger = logger;
        }

        /// <summary>
        /// 反添配种信息
        /// </summary>
        /// <param name="request">反添配种信息请求对象</param>
        /// <param name="cancellationToken"></param>
        /// <returns>反添配种信息响应对象</returns>
        public async Task<ResultT<MotherHybridization>> Handle(MotherHybridizationDetailCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var result = new ResultT<MotherHybridization>();
                var info = baseRepository.GetAll().FirstOrDefault(c => c.MotherHybridizationId == request.MotherHybridizationId);
                if (info != null)
                {
                    result.Item =  info;
                }
                return result;
            }
            catch (Exception ex)
            {

                throw;
            }
        }
    }
}
